import { Song } from "../services/data-types/common.types";
import { getRandomInt } from "./number";

export function isArray(arr:any[],target:any):boolean{
    return arr.indexOf(target) !== -1;
}
export function getElementOffset(el:HTMLElement):{top:number;left:number;}{
    if(!el.getClientRects().length){
        return{
            top:0,
            left:0
        }
    }
    const rect = el.getBoundingClientRect()
    const win = el.ownerDocument.defaultView
    return {
        top:rect.top + win!.pageYOffset,
        left:rect.left + win!.pageXOffset,
    }
}
export function shuffle<T>( arr: T[] ): T[] {
  const result = arr.slice();
  for (let i = 0; i < result.length; i++){
    // 0和i 之间的一个随机数
    const j = getRandomInt([0, i]);
    [result[i], result[j]] = [result[j], result[i]]
  }
  return result
}

export function findIndex (list:Song[], current:Song):number{
  return list.findIndex(item => item.id === current.id)
}

